<?php
declare (strict_types = 1);

namespace app\controller;

use app\middleware\AllowCrossDomain;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;

class Base extends AllowCrossDomain
{

    protected function initialize(){

//        鉴权
//        获取token 判断token是否存在 是否能够解码token
        $header=request()->header();
        if(!isset($header['token']) || empty($header['token'])){
            //return json(['code'=>0, 'msg'=>'token不存在'])->send();
            return json(['code'=>404, 'msg'=>'token不存在']);
        }
//        dump($header);

        //解码

        $key='api123456';
        $jwt = new Key($key,'HS256');

        $info = JWT::decode($header['token'],$jwt);
        $this->aid = $info->user_id;
//        $this->aid（该登录下的用户id）

    }

}
